#include "library.h"
#include "ui_library.h"
#include "user.h"
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>
Library::Library(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Library)
{
    ui->setupUi(this);

    model = new QSqlTableModel(this);
    model->setTable("book");
    model->select();
    ui->tableView->setModel(model);
}

Library::~Library()
{
    delete ui;
}

void Library::on_lineEdit_returnPressed()
{
    QString str = ui->lineEdit->text();
    if(str.isEmpty())
    {
        model->setTable("book");
    }
    else
    {
        if(ui->radioButtonId->isChecked())
            model->setFilter("BookId="+str);
        if(ui->radioButtonName->isChecked())
            model->setFilter("BookName='"+str+"'");
        if(ui->radioButtonAuthor->isChecked())
            model->setFilter("Author='"+str+"'");
    }
    model->select();
}

void Library::on_pushButtonBorrow_clicked()
{

}

void Library::on_pushButtonReturnUser_clicked()
{
    User *u = new User();
    u->show();
    close();
}

void Library::on_pushButton_clicked()
{
    close();
}
